/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.herenit.beijing.poc.login;

import com.herenit.beijing.dh2011.security.entity.SecurityMenu;
import java.io.IOException;
import java.util.List;
import org.openide.filesystems.*;
import org.openide.util.Exceptions;

/**
 *
 * @author Obama
 */
public class LoginService {

    private static final String ROOT_NODE = "Explorer";
    private static LoginService instance = new LoginService();

    public static LoginService getDefault() {
        return instance;
    }

    public void writeFileSystem(List<SecurityMenu> menus) {
        for (SecurityMenu menu : menus) {
            try {
                FileSystem fs = FileUtil.getConfigRoot().getFileSystem();
                FileObject fo = fs.findResource(menu.getMenuPath() );
                
              
                System.out.println(fo==null?"fo is null!":fo);
                if (menu.getDisplayName() != null) {
                    fo.setAttribute("displayName", menu.getDisplayName());
                }
                if (menu.getOriginalFile() != null) {
                    fo.setAttribute("originalFile", menu.getOriginalFile());
                }
                if (menu.getIcon() != null) {
                    fo.setAttribute("icon", menu.getIcon());
                }
                if (menu.getIcon() != null) {
                    fo.setAttribute("icon", menu.getIcon());
                }
                if (menu.getPosition() != 0) {
                    fo.setAttribute("position", menu.getPosition());
                }
            } catch (FileStateInvalidException ex) {
                Exceptions.printStackTrace(ex);
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
}
